# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Sascha Weaver <wzyboy@wzyboy.org>

# This font has four versions:
#
# * Multilingual versions with a default language: (OTF)
#   (We do not package them)
#   * Multilingual version with Japanese glyphs as default priority
#   * Multilingual version with Korean glyphs as default priority
#   * Multilingual version with Simplified Chinese glyphs as default priority
#   * Multilingual version with Traditional Chinese glyphs as default priority
# * Multilingual version combined the four versions above. (OTC)
#   (This version is "the best of the worlds", but it cannot be used in Windows)
#   -> adobe-source-han-serif-otc-fonts
# * Multilingual version compressed the 7 files into a single ttc file. (SuperOTC)
#   (We do not package them, as there's no difference from the OTC version in use)
# * Regional subsets with only characters used in CN, JP, KR or TW: (SubsetOTF)
#   (This version is smaller and has better compatibility)
#   * Regional subset with only Japanese glyphs + Latin
#   -> adobe-source-han-serif-jp-fonts
#   * Regional subset with only Korean glyphs + Latin
#   -> adobe-source-han-serif-kr-fonts
#   * Regional subset with only Simplified Chinese glyphs + Latin
#   -> adobe-source-han-serif-cn-fonts
#   * Regional subset with only Traditional Chinese glyphs + Latin
#   -> adobe-source-han-serif-tw-fonts

_pkgbase=adobe-source-han-serif
pkgbase=$_pkgbase-fonts
pkgname=($_pkgbase-jp-fonts $_pkgbase-kr-fonts $_pkgbase-cn-fonts $_pkgbase-tw-fonts $_pkgbase-hk-fonts $_pkgbase-otc-fonts)
pkgver=2.002
pkgrel=1
pkgdesc='Adobe Source Han Serif - A set of Pan-CJK fonts designed to complement Source Serif Pro'
arch=('any')
license=('custom:SIL')
url='https://github.com/adobe-fonts/source-han-serif'
source=("$pkgbase-$pkgver.tar.gz::https://github.com/adobe-fonts/source-han-serif/archive/${pkgver}R.tar.gz"
        44-source-han-serif-jp.conf
        44-source-han-serif-kr.conf
        44-source-han-serif-cn.conf
        44-source-han-serif-tw.conf
        44-source-han-serif-hk.conf
        44-source-han-serif-otc.conf)
sha512sums=('4176781251f14c5255dab2ea3f3045543d510830545b781f20b13e2398b4595c9a73d269285f5b35215e45576f9aeddd798d135ea4635a9627fd93ef744045ff'
            '2586f4bb85fe6c4089c65a4b972d5f543ac0459ca7160b7c23cb746720d59d7dcc81ec9eef762de34835fb8e40df65cee9c6ead628bd3bcb52544c517355a965'
            '21d8e6afcc537a1679e44e2438626202086ea766c7540ef3361b6c1a05e09870a37e0d3b1ad8300e66bc5c8138daf62b22f793089b37d1803279df2c31e6c2ff'
            '4ca2948c0801ba5f3a3955ff1d4fac1b08ab7c5c3eed8af8e73f71b488a80d2736318006859681c0ba5760048f5e89df700e46fc49710d02d43eafb5816e3db5'
            '95748793fc2228d45cb745c8f331613a7eaa724495ffc367a15206f3a6b6874d4108ecd20b89172c6cbf2616f25c52b9ee5f9a93dd38a058a2097efa30caf93b'
            'c6570248ef0f3ae49f7b253d5d723d7de014a3fea8e5e443babe2d5ef84ad8005f7024cd6359c6d51caaf90fc08a9566505a2752e83c79c8bae8a7f4786f00b0'
            '150ba43342a4ea0cf71cf6ccd9a2d7473fc017fe23cca9fbb87f5904ec647c5c8d9d440ce707f8ab8001efe9072ec7731030efc2ef81d0b8a2387e96a00e4a29')

_jp=(
SourceHanSerifJP-Bold.otf
SourceHanSerifJP-ExtraLight.otf
SourceHanSerifJP-Heavy.otf
SourceHanSerifJP-Light.otf
SourceHanSerifJP-Medium.otf
SourceHanSerifJP-SemiBold.otf
SourceHanSerifJP-Regular.otf
)
_kr=(
SourceHanSerifKR-Bold.otf
SourceHanSerifKR-ExtraLight.otf
SourceHanSerifKR-Heavy.otf
SourceHanSerifKR-Light.otf
SourceHanSerifKR-Medium.otf
SourceHanSerifKR-SemiBold.otf
SourceHanSerifKR-Regular.otf
)
_cn=(
SourceHanSerifCN-Bold.otf
SourceHanSerifCN-ExtraLight.otf
SourceHanSerifCN-Heavy.otf
SourceHanSerifCN-Light.otf
SourceHanSerifCN-Medium.otf
SourceHanSerifCN-SemiBold.otf
SourceHanSerifCN-Regular.otf
)
_tw=(
SourceHanSerifTW-Bold.otf
SourceHanSerifTW-ExtraLight.otf
SourceHanSerifTW-Heavy.otf
SourceHanSerifTW-Light.otf
SourceHanSerifTW-Medium.otf
SourceHanSerifTW-SemiBold.otf
SourceHanSerifTW-Regular.otf
)
_hk=(
SourceHanSerifHK-Bold.otf
SourceHanSerifHK-ExtraLight.otf
SourceHanSerifHK-Heavy.otf
SourceHanSerifHK-Light.otf
SourceHanSerifHK-Medium.otf
SourceHanSerifHK-SemiBold.otf
SourceHanSerifHK-Regular.otf
)
_otc=(
SourceHanSerif-Bold.ttc
SourceHanSerif-ExtraLight.ttc
SourceHanSerif-Heavy.ttc
SourceHanSerif-Light.ttc
SourceHanSerif-Medium.ttc
SourceHanSerif-SemiBold.ttc
SourceHanSerif-Regular.ttc
)

function _package {
    cd "$srcdir/source-han-serif-${pkgver}R"

    case "$1" in
        $_pkgbase-jp-fonts)
            fonts=(${_jp[@]})
            cd SubsetOTF/JP
            _fontconfig_filename=44-source-han-serif-jp.conf
            pkgdesc="Adobe Source Han Serif Subset OTF - Japanese OpenType/CFF fonts";;
        $_pkgbase-kr-fonts)
            fonts=(${_kr[@]})
            cd SubsetOTF/KR
            _fontconfig_filename=44-source-han-serif-kr.conf
            pkgdesc="Adobe Source Han Serif Subset OTF - Korean OpenType/CFF fonts";;
        $_pkgbase-cn-fonts)
            fonts=(${_cn[@]})
            cd SubsetOTF/CN
            _fontconfig_filename=44-source-han-serif-cn.conf
            pkgdesc="Adobe Source Han Serif Subset OTF - Simplified Chinese OpenType/CFF fonts";;
        $_pkgbase-tw-fonts)
            fonts=(${_tw[@]})
            cd SubsetOTF/TW
            _fontconfig_filename=44-source-han-serif-tw.conf
            pkgdesc="Adobe Source Han Serif Subset OTF - Traditional Chinese (Taiwan) OpenType/CFF fonts";;
        $_pkgbase-hk-fonts)
            fonts=(${_hk[@]})
            cd SubsetOTF/HK
            _fontconfig_filename=44-source-han-serif-hk.conf
            pkgdesc="Adobe Source Han Serif Subset OTF - Traditional Chinese (Hong Kong) OpenType/CFF fonts";;
        $_pkgbase-otc-fonts)
            fonts=(${_otc[@]})
            cd OTC
            _fontconfig_filename=44-source-han-serif-otc.conf
            pkgdesc="Adobe Source Han Serif - Pan-CJK OpenType/CFF Collection fonts";;
    esac

    # Prepare destination directory
    install -dm755 "$pkgdir/usr/share/fonts/adobe-source-han-serif"

    # Install fonts
    for font in "${fonts[@]}"; do
        install -m644 "$font" "$pkgdir/usr/share/fonts/adobe-source-han-serif"
    done

    # Install fontconfig fix
    install -d "$pkgdir/usr/share/fontconfig/conf.default"
    install -Dm644 "$srcdir/$_fontconfig_filename" "$pkgdir/usr/share/fontconfig/conf.avail/$_fontconfig_filename"
    ln -s ../conf.avail/$_fontconfig_filename "$pkgdir/usr/share/fontconfig/conf.default/$_fontconfig_filename"

    install -Dm644 "$srcdir"/source-han-serif-${pkgver}R/LICENSE.txt -t "$pkgdir"/usr/share/licenses/$1/
}

for _pkgname in ${pkgname[@]}; do
    eval "function package_$_pkgname() { _package $_pkgname; }"
done
